<template>
	<view>	
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="content">编辑</block>
		</cu-custom>
		<view v-if="page">
			<form @submit="formSubmit">
				<view class="wai">
					我的姓名：
					<view class="shurudiv">
						<input type="text" placeholder="请输入" name="name" class="shuru" :value="task.name"/>
					</view>
				</view>
				<view class="wai">
					联系电话：
					<view class="shurudiv">
						<input type="text" placeholder="请输入" name="phone" class="shuru" :value="task.phone"/>
					</view>
				</view>
				<view class="wai">
					收货地址：
					<view class="shurudiv">
						<input type="text" placeholder="请输入" name="address" class="shuru" :value="task.address"/>
					</view>
				</view>
				<view class="wai">
					送货时间：
					<view class="shurudiv">
						<input type="text" placeholder="请输入" name="time" class="shuru" :value="task.time"/>
					</view>
				</view>
				<view class="wai">
					取件地址：
					<view class="shurudiv">
						<input type="text" placeholder="请输入" name="locker" class="shuru" :value="task.locker"/>
					</view>
				</view>
				<view class="wai">
					取件号码：
					<view class="shurudiv">
						<input type="text" placeholder="请输入" name="code" class="shuru" :value="task.code"/>
					</view>
				</view>
				<view class="wai">
					任务赏金：
					<view class="shurudiv">
						<input type="text" placeholder="请输入" name="price" class="shuru" :value="task.price"/>
					</view>
				</view>
				<!-- <view class="cu-form-group align-start">
					<view class="title">标题</view>
					<textarea :value="task.title" name="title" maxlength="-1" placeholder="请输入标题"></textarea>
				</view>
				<view class="cu-form-group align-start">
					<textarea :value="task.content" name="content" maxlength="-1" placeholder="请输入内容"></textarea>
				</view> -->
				<view class="bg-white">
					<upimg-box @callParent="callImgList" :defaultImgsList="task.imgList"></upimg-box>
					<view class="padding flex flex-direction">
						<button class="cu-btn bg-blue shadow lg" form-type="submit">提交</button>
					</view>
				</view>
			</form>
		</view>
	</view>
</template>

<script>
	import mdate from "@/common/date.js"; 
	import upimgBox from "../../../components/upimgbox.vue";
	export default {
		components:{		 
			upimgBox
		},
		data:function(){
			return {
				imgsList:[],
				task:{},
				page:false,
				ssuserid:this.$store.getters.userInfo._id
			}
		},
		onLoad:function(ops){
			this.getPage(ops.id)
		},
		methods:{
			//上传图片
			callImgList:function(e){
				this.imgsList = e;			
			},
			getPage:function(tid){
				uniCloud.callFunction({
					name:"task",
					data:{
						cloudAction:"add",
						params:{
							ssuserid:this.ssuserid,
							id:tid
						}						
					}
				}).then((result)=>{
					var res = result.result;
					if(res.error){
						uni.showToast({
							title:res.message
						})
						return false
					}
					this.page = true
					this.task=res.data.data[0]
				})
			},
			formSubmit:function(e){
				var params=e.detail.value;
				if(this.imgsList.length == 0){
					this.imgsList = this.task.imgList
				}
				params.createTime=new Date().Format("yyyy-MM-dd hh:mm:ss");
				params.imgList=this.imgsList;
				console.log("要上传的",params);
				uniCloud.callFunction({
					name: 'task',
					data: {
						cloudAction:"save",
						id:this.task._id,
						params:params
					}
				}).then((res) => {
					uni.showToast({
						title:"修改成功"
					}) 
					uni.navigateBack()
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wai{
		display:flex;
		align-items:center ;
		margin: 10upx;
	}
	.shurudiv{
		width: 70%;
		display: flex;
		height: 60upx;
		align-items:center ;
		border:1px solid #c8c7cc;
		border-radius: 10upx;
		background-color: #FFFFFF;
	}
	.shuru{
		overflow:hidden;
		font-size: 14px;
		line-height: 2;
		padding-left: 20upx;
		
	}
</style>
